<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta name="decorator" content="sysDefault" />
<script
	src="${staticPath}/lib/jquery-datatables/1.9.4/js/jquery.dataTables.min.js"
	type="text/javascript"></script>
<link rel="stylesheet"
	href="${staticPath}/lib/ztree/3.5/css/zTreeStyle/zTreeStyle.css"
	type="text/css">	
<script type="text/javascript"
	src="${staticPath}/lib/ztree/3.5/js/jquery.ztree.all-3.5.js"></script>	
<script type="text/javascript">

var setting = {
		
		check: {
			enable: true,
			chkStyle: "radio",
			radioType: "level"
		},
		view : {
			selectedMulti : false,
			nameIsHTML : true
		},
		data : {
			simpleData : {
				enable : true,  //是否简单数据格式
				idKey: "id",   //id
				pIdKey: "pId"	//父ID
			}
		},
		callback : {
			onClick : onClick,
			onCheck : zTreeOnCheck
		}
};

function onClick(event, treeId, treeNode, clickFlag) {
	var category;
	if(clickFlag == 1){  //如果为选中状态
		category = treeNode.id
		var url = '${contextPath}/sys/news/category/getByCondition?category='+category;
		$("#iFrame1").attr("src", url);
	}
	else if(clickFlag == 0){  //取消选择     对当前选择节点按CTRL键
		var url = '${contextPath}/sys/news/category/getByCondition';
		$("#iFrame1").attr("src", url);
	}
}

var wholecgId = '';
function zTreeOnCheck(event, treeId, treeNode) {
	wholecgId = treeNode.id;
};

function funform() {
	var url = '${contextPath}/sys/news/category/addCategory?categoryId='+wholecgId;
	if(url!=null||url!=''){
		window.open(url, '_self');
	}
}

var treeNodes;
$(function(){
	$.ajax({
		async : false,
		cache:false,
		type: 'POST',
		dataType : "json",
		url: "${contextPath}/sys/news/category/categoryTree",
		error: function () {//请求失败处理函数
			alert('请求失败');
		},
		success:function(data){ //请求成功后处理函数。 
			treeNodes = data; //把后台封装好的简单Json格式赋给treeNodes
		}
	});
	$.fn.zTree.init($("#tree"), setting, treeNodes);
});
		
</script>

<style type="text/css">
.marginleft {
	margin-left: 2px;
	margin-bottom: 3px;
}

.content {
	width: 100%;
	padding: 0 0 3px;
	margin: 0;
	clear: both;
}

.pane1 {
	width: 200px;
	margin-right: 3px;
	margin-left: 3px;
	float: left;
}

.right {
	display: block;
	_width: auto;
	_float: left;
}

.left-rightsplit {
	height: 100% ； border:2px solid #9FBDD7;
}

.marginright {
	margin-right: 3px;
}

.ztree li span.button.switch.level0 {
	visibility: hidden;
	width: 1px;
}

.ztree li ul.level0 {
	padding: 0;
	background: none;
}
</style>
</head>
<body>
	<div class="content left-rightsplit">
		<div id="" class="pane1 marginleft" style="width:150px;">
			<fieldset>
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">
							新闻类别
							<button class="btn btn-success btn-sm pull-right" role="button"
								onclick="funform()">新增</button>
						</h3>
					</div>
				</div>
				<div style="position: absolute; top: 40px;">
					<ul id="tree" class="ztree"></ul>
				</div>

			</fieldset>
		</div>
		<div id="" class="right marginleft marginright">
			<div class="right-top">
				<fieldset>
					<iframe id="iFrame1" name="iFrame1" width="100%"
						style="height: 1000px" frameborder="no" border="0" marginwidth="0"
						marginheight="0" scrolling="no" allowtransparency="yes"
						src="${contextPath}/sys/news/category/getByCondition"></iframe>
				</fieldset>
			</div>

		</div>
	</div>

</body>
</html>